require('../less/mine.less')
document.ready(function () {
  window.utils.jumpPage('mine')
  // 获取节点
  let userImg = document.getElementById('userImg') //获取用户头像
  let userName = document.getElementById('userName') //获取用户头像
  let returnBtn = document.getElementById('returnBtn') //获返回按钮
  let masking = document.getElementById('masking') //获返回按钮
  let badgeBtn = document.getElementById('badgeBtn') //获取跳按钮
  let forthWad = document.getElementById('forthWad') //跳到运动数据按钮
  let spendC = document.getElementById('spendC') //消耗总的卡路里
  let sportTime = document.getElementById('sportTime') //总运动时间
  let close = document.getElementById('close') //关闭按钮
  let ranking = document.getElementById('ranking') //排名
  //获取用户id
  let id = JSON.parse(localStorage.getItem('userData')).userId
  console.log(id);
  let arr = JSON.parse(localStorage.getItem('userData'))
  // console.log(arr);
  localStorage.setItem('userData', JSON.stringify(arr)) //userData本地数据
  let localSport = JSON.parse(window.localStorage.getItem('sportsData'))
  spendC.textContent = localSport.calorie //消耗卡路里
  sportTime.textContent = localSport.times.toFixed(2)
  userInfor()

  function userInfor() {
    window.$http.get(`/users/accountinfo?userId=${id}`, function (res) {
      if (res.data.nickname) {
        userName.textContent = res.data.nickname;
      }
      if (res.data.imgurl) {
        userImg.src = 'http://139.9.177.51:8099' + res.data.imgurl
      }
      if (res.data.birthday) {
        arr.birthday = res.data.birthday
      };
      if (res.data.address) {
        arr.address = res.data.address
      }
      window.localStorage.setItem('userData', JSON.stringify(res.data))
    })


  }


  //徽章蒙版点击返回按钮
  returnBtn.addEventListener('click', function () {
    masking.style.display = 'none'
  })
  //点击跳转按钮,蒙版显示
  badgeBtn.addEventListener('click', function () {
    masking.style.display = 'block'

  })

  // 点击按钮.跳转到登录
  forthWad.addEventListener('click', function () {
    window.location.href = './sportsData.html'
  })

  close.addEventListener('click', function () {
    window.localStorage.clear()
    window.location.href = './login.html'
  })
  //排名
  // ranking.textContent=

  console.log(id);
  // ajax调用
  window.$http.get(`/headPageInfo?userId=${id}`, function (res) {
    if (res.status == 0) {
    ranking.textContent=res.data.rank
    console.log(res.data);
    }
  })






})